package com.easy.controller;

import com.easy.bean.Message;
import com.easy.service.MessageService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("message")
public class MessageController {

    @Autowired
    MessageService messageService;

    @GetMapping("page")
    public Result page(Page page, Message message) {
        Object obj = messageService.page(page, message);
        return Result.success(obj);
    }

    @PostMapping
    public Result add(@RequestBody Message message) {
        Object obj = messageService.add(message);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Message message) {
        Object obj = messageService.edit(message);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id) {
        Object obj = messageService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = messageService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Message message) {
        Object obj = messageService.all(message);
        return Result.success(obj);
    }
}
